package com.supervision.manage.mapper.sqlprovider

import com.supervision.domain.bean.po.SmsPO
import org.apache.commons.lang3.StringUtils

class SmsTemplateSqlProvider {

    fun getSmsTemplateList(param: HashMap<String, Any>): String {
        val po = param["po"] as SmsPO
        val limitSql = param["limitSql"] as String

        val sql = StringBuilder()
        if (limitSql.isEmpty()) {
            sql.append(" select count(*) ")
        } else {
            sql.append(" select st.*  ")
        }
        sql.append(" from sms_template st ")
        sql.append(" where st.weight >= 0 ")
        if (po.templateId.isNotEmpty()) {
            sql.append(" and st.template_id = #{po.templateId} ")
        }
        if (po.type > 0) {
            sql.append(" and st.type = #{po.type} ")
        }

        sql.append(" order by st.id desc ")

        return sql.toString() + StringUtils.defaultString(limitSql, StringUtils.EMPTY)
    }
}